/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <boost/scoped_ptr.hpp>
#include <lib3d/material/Shaders.h>
#include <lib3d/Math_lib3d.h>
#include <resource/ActiveMultithreaded.h>
#include <NoCopy.h>
#include <SimpleArray.h>
#include <SharedRep.h>
#include <map>

namespace liba {
namespace lib3d {
namespace model {

class Model : private xml::ObjectANSI, public SharedPrecachedRepBase
{
public:
	explicit Model(const filesystem::String & name);
	~Model();

	static const Atom position_name;
	static const Atom normal_name;
	static const Atom face_normal_name;
	static const Atom u_tangent_name;
	static const Atom v_tangent_name;
	static const Atom diffuse_name;
	static const Atom specular_name;
	static const Atom uv0_name;
	static const Atom uv1_name;
	static const Atom uv2_name;
	static const Atom uv3_name;
	static const Atom weights0_name;
	static const Atom weights1_name;
	static const Atom weights2_name;
	static const Atom indices0_name;
	static const Atom indices1_name;
	static const Atom indices2_name;
	static const Atom indices3_name;
	static const Atom index_name;

	const SimpleArray<float> * find_value_float(const Atom & value_name)const;
	const SimpleArray<int> * find_value_int(const Atom & value_name)const;

	void add_value( const Atom & value_name, const SimpleArray<float> & value );
	void add_value( const Atom & value_name, const SimpleArray<int> & value );

	void load(const filesystem::String & name);
	const Sphere & get_bounding_sphere()const
	{
		return bounding_sphere;
	}
	
	//TODO: write code to reload model
	void unload_model();	//flushes loaded buffer to save memory
private:
	typedef std::map< Atom, SimpleArray<float> > Floats;
	typedef std::map< Atom, SimpleArray<int> > Ints;
	Floats floats;
	Ints ints;

	filesystem::String name;

	Sphere bounding_sphere;
	const SimpleArray<float> dumb_floats;
	const SimpleArray<int> dumb_ints;

	boost::scoped_ptr<resource::ActiveMultithreaded> res;
};

} // namespace model
} // namespace lib3d
} // namespace liba
using namespace liba;

